﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ListNetRanker
{
    public class Document
    {
        /** The qid. */
        public int qid;

        /** The relevance. */
        public int relevance;

        /** The features. */
        public List<Double> features;


        //Create a new document
        public Document(int qid, int rel, List<Double> f)
        {
            this.features = f;
            this.relevance = rel;
            this.qid = qid;
        }

        //Parse record from raw data
        public static Document Parse(string line)
        {
            List<Double> list = new List<Double>();
            int rel = 0;
            int qid = 0;

            string[] strs = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            rel = int.Parse(strs[0]);
            qid = int.Parse(strs[1].Split(':')[1]);

            for (int i = 2; i < strs.Length; i++)
            {
                list.Add(double.Parse(strs[i].Split(':')[1]));
            }

            return new Document(qid, rel, list);
        }
    }
}
